package br.com.felix.fwt.ui;

import java.io.PrintWriter;

import br.com.felix.fwt.ui.exception.ComponentRenderException;
import br.com.felix.fwt.ui.javascript.Hide;
import br.com.felix.fwt.ui.javascript.Javascript;
import br.com.felix.fwt.ui.javascript.JavascriptListener;
import br.com.felix.fwt.ui.javascript.MoveTo;
import br.com.felix.fwt.ui.javascript.Show;

/**
 * The Class Panel can be defined as a DIV.
 * It will be used in the same way: to group components...
 */
public class Panel extends BaseComponent{

	
	private static final long serialVersionUID = -3031031408763650033L;

	/**
	 * Instantiates a new panel.
	 */
	public Panel(){
		this.cssClass = "fwtpanel";
	}
	
	/* (non-Javadoc)
	 * @see br.com.felix.fwt.ui.BaseComponent#write(java.io.PrintWriter)
	 */
	@Override
	public void write(PrintWriter out) throws ComponentRenderException {
		if(!authorized()) return;
		out.write("\n<div class=\"");
		out.write(cssClass);
		out.write("\" ");
		out.write("id=\""); 
		out.write(getName());
		out.write("\" ");

		if(javascripts != null){
			for(JavascriptListener js: javascripts){
				out.write(js.script());
			}
		}
		if(style!=null){
			out.write(style);
		}
		out.write(">");
		writeChilds(out);
		out.write("\n</div>");
	}

	/**
	 * Hide.
	 * 
	 * @return the javascript
	 */
	public Javascript hide() {
		return new Hide(this);
	}

	/**
	 * Show.
	 * 
	 * @return the javascript
	 */
	public Javascript show() {
		return new Show(this);
	}
	
	/**
	 * Move to.
	 * 
	 * @param top the top
	 * @param left the left
	 * 
	 * @return the javascript
	 */
	public Javascript moveTo(int top, int left){
		return new MoveTo(this,top,left);
	}
	
	

}
